/**
 * Created by wzh on 2016/8/10.
 */
swan_pc
    .factory('OrgOpp', function ($resource, DateUtils) {
        return $resource('/api/orgOpportunitys/:infoid', {infoid:'@infoid'}, {
            'query': { method: 'GET', isArray: true},
            'queryAll': {
                method: 'GET',
                transformResponse: function (data) {
                    data = angular.fromJson(data);
                    data.opportunity.oppCode=data.opportunity.oppCode.indexOf("^")>=0?data.opportunity.oppCode.substr(1):data.opportunity.oppCode
                    //data.companyBaseInfo.foundDate = DateUtils.convertLocaleDateFromServer(data.companyBaseInfo.foundDate);
                    return data;
                }
            },
            'update': {
                method: 'PUT',
                transformRequest: function (data) {
                    //data.companyBaseInfo.foundDate = DateUtils.convertLocaleDateToServer(data.companyBaseInfo.foundDate);
                    return angular.toJson(data);
                }
            },
            'save': {
                method: 'POST',
                transformRequest: function (data) {
                    //data.companyBaseInfo.foundDate= DateUtils.convertLocaleDateToServer(data.companyBaseInfo.foundDate);
                    return angular.toJson(data);
                }
            },
            'delete':{
                method:'DELETE'
            },
            'queryByOrgnization': {
                method: 'GET',
                isArray: true,
                url:'api/organizations/:infoid/orgOpportunitys'
            },
            'queryOppDate': { method: 'GET',
                isArray: true,
                transformResponse: function (data) {
                    data = angular.fromJson(data);
                    _.forEach(data,function(item){
                        item.date=DateUtils.convertLocaleDateFromServer(item.date);
                    })
                    return data;
                },
                url:'api/orgOpportunitys/:infoid/opportunityDates'
            },
            'entityOwner':{
                isArray: true,
                transformResponse: function (data) {
                    data = angular.fromJson(data);
                    return data;
                },
                url:'/api/members/:infoid/entityOwners'
            }
        });
    })
    .factory('OppDate', function ($resource, DateUtils) {
        return $resource('/api/opportunityDates/:infoid', {infoid:'@infoid'}, {
            'query': { method: 'GET', isArray: true},
            'queryAll': {
                method: 'GET',
                transformResponse: function (data) {
                    data = angular.fromJson(data);
                    //data.companyBaseInfo.foundDate = DateUtils.convertLocaleDateFromServer(data.companyBaseInfo.foundDate);
                    return data;
                }
            },
            'update': {
                method: 'PUT',
                transformRequest: function (data) {
                    data.date= DateUtils.convertLocaleDateToServer(data.date);
                    return angular.toJson(data);
                }
            },
            'save': {
                method: 'POST',
                transformRequest: function (data) {
                    data.date= DateUtils.convertLocaleDateToServer(data.date);
                    console.log(data.date)
                    return angular.toJson(data);
                }
            },
            'delete':{
                method:'DELETE'
            },
        });
    });